package org.etherframework.tests.utils
{
	import flash.errors.IllegalOperationError;
	
	import org.etherframework.core.IModule;
	
	public class ModuleHierarchy
	{
		private var _info:ModuleInfo;
		private var _chain:Vector.<ModuleInfo>;
		
		public function ModuleHierarchy(chain:Vector.<ModuleInfo>)
		{
			_chain = chain;
			_info = _chain.shift();
		}
		
		public function get info():ModuleInfo
		{
			return _info;
		}
		
		public function get module():IModule
		{
			return _info.module;
		}
		
		public function next():ModuleHierarchy
		{
			if (!_chain.length)
				throw new IllegalOperationError("End of hierarchy.");
			
			return new ModuleHierarchy(_chain.concat());
		}
	}
}